﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace QiAdmin.Core.Utils
{
    public class RunNameUtil
    {
        public static MethodBase GetMethodBase(StackTrace stackTrace)
        {
            var methodBase = stackTrace.GetFrame(1)?.GetMethod();
            if (methodBase == null)
            {
                throw new SystemException("解析运行数据失败");
            }
            return methodBase;
        }
        public static string GetNameSpace(StackTrace stackTrace)
        {
            return GetMethodBase(stackTrace).DeclaringType.Namespace;
        }
        public static string GetClass(StackTrace stackTrace)
        {
            return GetMethodBase(stackTrace).DeclaringType.Name;
        }
        public static string GetMethod(StackTrace stackTrace)
        {
            return GetMethodBase(stackTrace).Name;
        }

        public static string GetClassAndMethod(StackTrace stackTrace)
        {
            var methodBase = GetMethodBase(stackTrace);
            return methodBase.DeclaringType.Name + "." + methodBase.Name;
        }
    }
}
